package com.gxa.modules.sys.controller;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

//@RestController
public class TestMq {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("/send04/{msg}/{delay}")
    public String sendMessage(@PathVariable("msg") String msg, @PathVariable("delay") Integer delay){
        MessagePostProcessor messagePostProcessor = new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setDelay(delay);
                return message;
            }
        };

        this.rabbitTemplate.convertAndSend("exchange-delay","delay-xx",msg,messagePostProcessor);

        return "发送成功";
    }
}
